<?php
namespace app\Logic\Layui\ServiceProviders;

use app\Logic\Container;
use app\Logic\Logic;
use App\Model\MenuModel;
use Illuminate\Http\Request;

class Menu extends Logic implements ServiceProviderInterface
{

    public $app;

    public function __construct($app)
    {
        $this->app = $app;
    }


    /**
     * @param Container $app
     */
    public static function register(Container $app)
    {
        !isset($app->values['Menu']) && $app->values['Menu'] = function (Request $app){
            return new self($app);
        };
    }


    public function lists()
    {
        $data = $this->app->input();

        $menuModel = new MenuModel();

        return $menuModel->lists($data);
    }


    public function create()
    {
        $data = $this->app->input();

        $menuModel = new MenuModel();

        $menuModel->create($data);

    }


    public function edit($id)
    {
        $data = $this->app->input();

        $menuModel = new MenuModel();

        $menuModel->edit($id, $data);
    }


    public function find($id)
    {
        $menuModel = new MenuModel();
        $condition = ['id'=>$id];
        $field = ['name','pid','url','icon','remark','is_show'];

        return $menuModel->find($condition, $field);
    }


    public function delete()
    {
        $id = $this->app->input('id');

        $menuModel = new MenuModel();

        return $menuModel->del($id);
    }


    public function all()
    {
        $menuModel = new MenuModel();

        return $menuModel->get();
    }



    public function normMenu()
    {
        $menuModel = new MenuModel();

        return $menuModel->normMenu();
    }


    public function update($condition, $data)
    {
        $menuModel = new MenuModel();

        $menuModel->saveMenu($condition, $data);
    }

    public function menu()
    {
        $menuModel = new MenuModel();

        return $menuModel->menu();
    }


    /**
     * @param $name
     * @param $arguments
     * @return mixed
     */
    public function __call($name,$arguments)
    {
        return $this->app->$name(...$arguments);
    }
}